package com.kehutong.wxapi.request;

import org.coraframework.json.JSON;
import org.coraframework.json.JSONObject;
import org.coraframework.json.annotation.JSONField;
import org.coraframework.util.Objects;

import java.util.ArrayList;
import java.util.List;

/**
 * 获取「群聊数据统计」数据按自然日聚合的方式请求对象
 * @author: liukunlong
 * @date: 2021-03-05 10:36
 */
public class GroupChatStatisticGroupByDayRequest {
    /**
     * 调用接口凭证
     */
    private String accessToken;

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    /**
     * 起始日期的时间戳，填当天的0时0分0秒（否则系统自动处理为当天的0分0秒）。取值范围：昨天至前180天。
     */ /**
     * day_begin_time : 1600272000
     * day_end_time : 1600358400
     * owner_filter : {"userid_list":["zhangsan"]}
     */

    @JSONField(name = "day_begin_time")
    private Integer dayBeginTime;
    /**
     * 结束日期的时间戳，填当天的0时0分0秒（否则系统自动处理为当天的0分0秒）。取值范围：昨天至前180天。
     * 如果不填，默认同 day_begin_time（即默认取一天的数据）
     */
    @JSONField(name = "day_end_time")
    private Integer dayEndTime;
    /**
     * 群主过滤，如果不填，表示获取全部群主的数据
     */
    @JSONField(name = "owner_filter")
    private OwnerFilterDTO ownerFilter;

    public Integer getDayBeginTime() {
        return dayBeginTime;
    }

    public void setDayBeginTime(Integer dayBeginTime) {
        this.dayBeginTime = dayBeginTime;
    }

    public Integer getDayEndTime() {
        return dayEndTime;
    }

    public void setDayEndTime(Integer dayEndTime) {
        this.dayEndTime = dayEndTime;
    }

    public OwnerFilterDTO getOwnerFilter() {
        return ownerFilter;
    }

    public void setOwnerFilter(OwnerFilterDTO ownerFilter) {
        this.ownerFilter = ownerFilter;
    }

    public static class OwnerFilterDTO {
        /**
         * 群主ID列表。最多100个
         */
        @JSONField(name = "userid_list")
        private List<String> useridList;

        public List<String> getUseridList() {
            return useridList;
        }

        public void setUseridList(List<String> useridList) {
            this.useridList = useridList;
        }
    }

    public static void main(String[] args) {
        //对象属性为null,转json会排除掉
        GroupChatStatisticGroupByDayRequest groupChatStatisticGroupByDayRequest=new GroupChatStatisticGroupByDayRequest();
        groupChatStatisticGroupByDayRequest.setDayBeginTime(1600272000);
        OwnerFilterDTO ownerFilter=new OwnerFilterDTO();
        List<String> useridList=new ArrayList<>();
        useridList.add("zhangsan");
        ownerFilter.setUseridList(useridList);
        groupChatStatisticGroupByDayRequest.setOwnerFilter(ownerFilter);

        JSONObject body = new JSONObject();
        body.put("day_begin_time",groupChatStatisticGroupByDayRequest.getDayBeginTime());

        if (Objects.nonNull(groupChatStatisticGroupByDayRequest.getDayEndTime())) {
            body.put("day_end_time",groupChatStatisticGroupByDayRequest.getDayEndTime());
        }

        if (Objects.nonNull(groupChatStatisticGroupByDayRequest.getOwnerFilter())) {
            body.put("owner_filter",groupChatStatisticGroupByDayRequest.getOwnerFilter());
        }

        System.out.println(body.toJSONString());
        System.out.println(JSON.toJSONString(groupChatStatisticGroupByDayRequest));
    }
}
